const MerchantDao = require('../dao/merchant.dao');
const FoodDao = require('../dao/food.dao');

function login(name, password, callback) {
    MerchantDao.checkLoginInfo(name, password, function (doc) {
        callback(doc);
    });
}

function register(name, password, address, headPic, idCardPic, callback) {
    MerchantDao.insertMerchant(
        {
            name: name,
            password: password,
            address: address,
            headPic: headPic,
            idCardPic: idCardPic
        },
        function (doc) {
            callback(doc);
        }
    );
}

function getMerchantById(id, callback) {
    MerchantDao.getMerchantById(id, function (doc) {
        callback(doc);
    });
}

function getMerchantList(callback) {
    MerchantDao.getMerchantList(function (doc) {
        callback(doc);
    });
}

function getMerchantListByFoodtype(id, callback) {
    FoodDao.findMerchantByFoodtypeId(id, function (res) {
        callback(res);
    });
}

function removeMerchantById(id, callback) {
    MerchantDao.deleteMerchantById(id, function (doc) {
        callback(doc);
    });
}

function updateMerchant(id, name, password, address, headPic, idCardPic, callback) {
    MerchantDao.updateMerchant(
        {
            _id: id,
            merchantName: name,
            password: password,
            address: address,
            headPic: headPic,
            idCardPic: idCardPic
        },
        function (doc) {
            callback(doc);
        }
    );
}

module.exports = {
    login: login,
    register: register,
    getMerchantById: getMerchantById,
    getMerchantList: getMerchantList,
    removeMerchantById: removeMerchantById,
    updateMerchant: updateMerchant,
    getMerchantListByFoodtype: getMerchantListByFoodtype
}